package demo.bocweb.com.book;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import demo.bocweb.com.book.bean.book.BookItemBean;
import demo.bocweb.com.book.contract.BookContract;
import demo.bocweb.com.book.presenter.BookPresenter;
import demo.bocweb.com.sdk.base.BasePresenter;
import demo.bocweb.com.sdk.base.activity.BaseMVPActivity;
import demo.bocweb.com.sdk.service.IUserModuleService;

/**
 * 豆瓣书籍列表
 * Created by zhelun on 2018/1/19.
 */
@Route(path = "/book/main_activity")
public class BookListActivity extends BaseMVPActivity<BookContract.BookPresenter, BookContract.BookModel> implements BookContract.IBookView {
    String tag = "文学";
    @BindView(R2.id.lv_book)
    ListView lvBook;
    @BindView(R2.id.btn)
    Button btn;
    @BindView(R2.id.tv_name)
    TextView tvName;
    private BookAda bookAda;
    private List<BookItemBean> list = new ArrayList<>();

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return BookPresenter.newInstance();
    }



    @Override
    protected void initData() {
        super.initData();
        bookAda = new BookAda(list, this);
        lvBook.setAdapter(bookAda);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                IUserModuleService service = ARouter.getInstance().navigation(IUserModuleService.class);
                if (service != null) {
                    tvName.setText(service.getUserName());
                } else {
                    tvName.setText("");
                }

            }
        });
        mPresenter.getBookList(tag, 1, 20);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_book_list;
    }

    @Override
    public void updateListData(List<BookItemBean> dataes) {
        list.clear();
        list.addAll(dataes);
        bookAda.notifyDataSetChanged();
    }

}
